﻿using System.Collections;
using UnityEngine;
using UnityEngine.Events;
 

/// <summary>
/// 手机摇一摇的输入事件
/// </summary>
public class InputPhoneVibrate : MonoBehaviour
{ 
	//记录上一次的重力感应的Y值
	private float old_x = 0;
	//记录当前的重力感应的Y值
	private float new_x;
	//当前手机晃动的距离
	private float currentDistance = 0;
 
	//手机晃动的有效距离
    public float distance = 1.0f;

    public UnityEvent OnPhoneVibrate;

 
    void Update()
    {
        new_x = Input.acceleration.x;
		currentDistance = new_x - old_x;
        old_x = new_x;
 
		if (currentDistance > distance)
		{
			//实现手机晃动震动效果 
			OnPhoneVibrate.Invoke();

        }
    }
}
